package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.Grad;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.impl.GradService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/*
功能描述:
作者：14136
创造日期：2024/12/10
*/
//public class SysGradController {


@Controller
@Slf4j
@RequestMapping("/system/grad")
public class SysGradController extends BaseController {
    private String prefix = "system/grad";
    @Autowired
    private GradService gradService;
    @RequiresPermissions("system:grad:view")
    @GetMapping()
    public String user() {
        return prefix + "/post";
    }

    @RequiresPermissions("system:grad:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Grad grad ) {
        startPage();
        List<Grad> list = gradService.selectGradList(grad);
            return getDataTable(list);
        }

    @RequiresPermissions("system:grad:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        mmap.put("grad", gradService.selectGradById(id));
        return prefix + "/edit";
    }

    @RequiresPermissions("system:grad:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult saveSysGrad(@Valid Grad grad) {
        //log.info("Received SysUser object: {}", grad);
        // 处理保存逻辑
        gradService.save(grad);
        return toAjax(1);
        //return ResponseEntity.ok("保存成功");
    }

    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }
    @RequiresPermissions("system:grad:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSysGrad(@Validated Grad grad) {
        gradService.addSave(grad);
        return  toAjax(1);
    }

    @GetMapping("/remove")
    public String remove()
    {
        return prefix + "/remove";
    }

    @RequiresPermissions("system:grad:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(@Valid Integer[] ids ) {
         gradService.deleteUserByIds(ids);
        return  toAjax(1);
    }
    @RequiresPermissions("system:grad:list")
    @GetMapping("/studentIds")
    @ResponseBody
    public List<Grad> getStudentIds() {
        return gradService.getStudentIds();
    }



}


